package com.brkj.course;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import com.brkj.course.model.DS_CourseClassInfo;
import com.brkj.course.model.DS_CourseClassInfoSecond;
import com.brkj.main.R;
import com.brkj.model.DS_CourseClass;
import com.dgl.sdk.util.Utils;

import java.util.List;

public class CourseClassSecondAdapter extends BaseAdapter{
	private ListItemView listItemView;
	protected LayoutInflater listContainer;
	private Context context;
    private CourseViewClass courseViewClass;
	private List<DS_CourseClassInfo> courseClassList;

	public CourseClassSecondAdapter(Context context, List<DS_CourseClassInfo> courseClassList, CourseViewClass courseViewClass){
		this.context = context;
		this.courseClassList = courseClassList;
		this.courseViewClass = courseViewClass;

		listContainer = LayoutInflater.from(context);
	}
	
	private static class ListItemView{
		public TextView courseClassName;
		public TextView courseNum;
	};
	
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return courseClassList.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// 自定义视图
		listItemView = new ListItemView();
		// 获取list_item布局文件的视图
		if (convertView == null) {
			convertView = listContainer.inflate(R.layout.course_class_second_item, null);
			// 获取控件对象
			listItemView.courseClassName = (TextView) convertView.findViewById(R.id.courseClassName);
			listItemView.courseNum = (TextView) convertView.findViewById(R.id.courseNum);

			// 设置控件集到convertView
			convertView.setTag(listItemView);
		} else {
			listItemView = (ListItemView) convertView.getTag();
		}
		
		listItemView.courseClassName.setText(courseClassList.get(position).getName());

        listItemView.courseNum.setText(courseClassList.get(position).getCourseNum()+"课");


        convertView.setOnClickListener(new myOnclickListener(position));


		return convertView;
	}
	
	class myOnclickListener implements OnClickListener{
		private int position;
		
		public myOnclickListener(int position){
			this.position = position;
		}

		
		@Override
		public void onClick(View v) {
            courseViewClass.infoClassClick(courseClassList.get(position));
		}
		
	}
}
